#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5;

int n, m;
int g[N][N];
int check_row(int i) {
  int cnt[3] = {0};
  rep(j, 1, 3) cnt[g[i][j]]++;
  if (cnt[1] == 3) return 1;
  if (cnt[2] == 3) return 2;
  if (cnt[1] && cnt[2]) return 3;
  return 0;
}
int check_col(int j) {
  int cnt[3] = {0};
  rep(i, 1, 3) cnt[g[i][j]]++;
  if (cnt[1] == 3) return 1;
  if (cnt[2] == 3) return 2;
  if (cnt[1] && cnt[2]) return 3;
  return 0;
}
int check_cross(int dx, int dy) {
  int cnt[3] = {0};
  rep(i, -1, 1) cnt[g[2 + dx * i][2 + dy * i]]++;
  if (cnt[1] == 3) return 1;
  if (cnt[2] == 3) return 2;
  if (cnt[1] && cnt[2]) return 3;
  return 0;
}
void solve() {
  rep(i, 1, 3) rep(j, 1, 3) {
    char c;
    cin >> c;
    g[i][j] = c == '.' ? 0 : (c == 'X' ? 1 : 2);
  }
  int cnt[4] = {0}, now = 0;
  rep(i, 1, 3) rep(j, 1, 3) cnt[g[i][j]]++;
  if (cnt[1] != cnt[2] && cnt[1] != cnt[2] + 1) {
    cout << "illegal" << endl;
    return;
  }
  if (cnt[1] == cnt[2])
    now = 2;
  else
    now = 1;
  int res[4] = {0};
  rep(i, 1, 3) {
    res[check_row(i)]++;
    res[check_col(i)]++;
  }
  res[check_cross(1, 1)]++;
  res[check_cross(1, -1)]++;

  if (res[1] && res[2]) {
    cout << "illegal" << endl;
  } else if (res[1]) {
    if (now != 1)
      cout << "illegal" << endl;
    else
      cout << "the first player won" << endl;
  } else if (res[2]) {
    if (now != 2)
      cout << "illegal" << endl;
    else
      cout << "the second player won" << endl;
  } else if (cnt[0] == 0) {
    cout << "draw" << endl;
  } else if (now == 2) {
    cout << "first" << endl;
  } else {
    cout << "second" << endl;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}